#include<iostream>
#include "Lldi.h"

Lldi::Lldi()
  {
    this->p = this->q = 0;
    std::cout<<"\nLista l.l.d.i. a fost creata!\n";
  }

void Lldi::listare()
  {
    Nod *r;
    r = this->p;
    if(r != 0)
      {
	std::cout<<"\nLista:\n\n";
	while(r != 0)
	  {
	    std::cout<<"Cheie :"<<r->data<<"\n";
	    r = r->urm;
	  }
	std::cout<<"\n";
      }
      else std::cout<<"\nLista este vida!\n";
  }

bool Lldi::operator==(const Lldi& l)
  {
    Nod *r1, *r2;
    r1 = this->p;
    r2 = l.p;
    while(r1 != this->q && r2 != l.q)
      {
        if(r1->data != r2->data) return false;
	r1 = r1->urm;
	r2 = r2->urm;
      }
    if((r1 == 0 && r2 != 0) || (r1 != 0 && r2 == 0)) return false;
    return true;
  }

bool Lldi::operator!=(const Lldi& l)
  {
    Nod *r1, *r2;
    r1 = this->p;
    r2 = l.p;
    while(r1 != this->q && r2 != l.q)
      {
        if(r1->data == r2->data) return false;
	r1 = r1->urm;
	r2 = r2->urm;
      }
    if((r1 == 0 && r2 != 0) || (r1 != 0 && r2 == 0)) return false;
    return true;
  }

void Lldi::operator+(Nod* d)
  {
    if(this->q == 0)
      {
        d->urm = d-> ant = 0;
	this->p = this->q = d;
      }
      else
        {
	  this->q->urm = d;
	  d->ant = this->q;
	  d->urm = 0;
	  this->q = d;
	}
  }
